<?php
if ( !$max_page ) {
if ( isset($max_num_pages) ) $max_page = $max_num_pages;
else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = $max_num_pages = ceil($numposts / $posts_per_page);
}
}
if ( !$paged ) $paged = 1;
$nextpage = intval($paged) + 1;
if ( !is_single() && ( empty($paged) || $nextpage <= $max_page ) ) $there_are_next_posts = true;
if ( !is_single() && $paged > 1 ) $there_are_previous_posts = true;
?>
<?php if ( $there_are_next_posts || $there_are_previous_posts ) : ?>
<div class="post">
<?php if ( $there_are_next_posts ) : ?>
<p class="left"><a href="<?php next_posts($max_page) ?>">&laquo; Older articles</a></p>
<?php else : // $there_are_next_posts ?>
<p class="left">No older articles</p>
<?php endif // $there_are_next_posts ?>
<?php if ( $there_are_previous_posts ) : ?>
<p class="right"><a href="<?php previous_posts() ?>">Newer articles &raquo;</a></p>
<?php else : // $there_are_previous_posts ?>
<p class="right">No newer articles</p>
<?php endif // $there_are_previous_posts ?>
<p>&nbsp;</p>
</div>
<?php endif // $there_are_next_posts || $there_are_previous_posts ?>
